package engine.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Manages lists of attributes.
 * 
 * @author Kyle_Solo
 */
public class AttributeList {
	private final Map<String, Double> doubleAttributes;
	private final Map<String, String> stringAttributes;

	/**
	 * Creates a new, empty attributes container
	 */
	public AttributeList() {
		doubleAttributes = new HashMap<String, Double>();
		stringAttributes = new HashMap<String, String>();
	}

	/**
	 * Gets the value of the specified attribute
	 * 
	 * @param attribute
	 *            the attribute to get
	 * @return the value of this attribute as a double, or null if the attribute does not exist
	 */
	public double getDouble(String attribute) {
		return doubleAttributes.get(attribute);
	}

	/**
	 * Gets the value of the specified attribute
	 * 
	 * @param attribute
	 *            the attribute to get
	 * @return the value of this attribute as a string, or null if the attribute does not exist
	 */
	public String getString(String attribute) {
		return stringAttributes.get(attribute);
	}

	/**
	 * @param attribute
	 *            the attribute to search for
	 * @return whether this AttributeList contains the specified double attribute
	 */
	public boolean hasDouble(String attribute) {
		return doubleAttributes.containsKey(attribute);
	}

	/**
	 * @param attribute
	 *            the attribute to search for
	 * @return whether this AttributeList contains the specified string attribute
	 */
	public boolean hasString(String attribute) {
		return stringAttributes.containsKey(attribute);
	}

	/**
	 * Adds/sets an attribute to a double value
	 * 
	 * @param attribute
	 *            the attribute to modify
	 * @param value
	 *            the new value of this attribute
	 * @return the previous value, or null
	 */
	public double setDouble(String attribute, double value) {
		return doubleAttributes.put(attribute, value);
	}

	/**
	 * Adds/sets an attribute to a string value
	 * 
	 * @param attribute
	 *            the attribute to modify
	 * @param value
	 *            the new value of this attribute
	 * @return the previous value, or null
	 */
	public String setString(String attribute, String value) {
		return stringAttributes.put(attribute, value);
	}
}
